package com.ebuy.shopping.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ebuy.shopping.mapper.ProductMapper;
import com.ebuy.shopping.model.Product;

@Service
public class ProductService implements IProductService
{
    @Autowired
    private ProductMapper productMapper;

    @Override
    public Product load(int id) throws Exception
    {
        return productMapper.selectByPrimaryKey(id);

    }

    @Override
    public int add(Product product) throws Exception
    {
        return productMapper.insert(product);

    }

    @Override
    public int update(Product product) throws Exception
    {
        return productMapper.updateByPrimaryKey(product);

    }

    @Override
    public List<Product> getProductsByCategoryId(Integer id) throws Exception
    {

        return productMapper.getProductsByCategoryId(id);

    }

    @Override
    public List<Product> getProductsBySaleType(Integer saleType)
            throws Exception
    {

        return productMapper.getProductsBySaleType(saleType);

    }

    @Override
    public List<Product> getProducts() throws Exception
    {

        return productMapper.getProducts();

    }

    @Override
    public int deleteByPrimaryKey(Integer id)
    {

        return productMapper.deleteByPrimaryKey(id);

    }

}
